<?php

namespace App\Admin\Actions\ShopProduct;

use App\Library\Logic\OperateLogLogic;
use App\Library\Models\AdminShopProductModel;
use Encore\Admin\Actions\RowAction;
use Encore\Admin\Facades\Admin;

class ShopProductDownStatusAction extends RowAction
{
    public $name = '下架';

    public function handle(AdminShopProductModel $model)
    {
        $model->product_status = 1;
        $model->product_offline_time = time();
        $model->operated_at = now();
        $model->save();
        OperateLogLogic::add(Admin::user()->user_id, 'admin.product.down');
        return $this->response()->success('操作成功')->refresh();
    }

    public function dialog(): void
    {
        $this->confirm('确定下架吗?');
    }
}
